<?php 
error_reporting(0);
/*
a) Please calculate the percentage of each student for each month and 
display the values in toppers order (First, Second and Third) and the status also pass / fail. (minimum mark of pass is 40)
b) Can you say which student get progressed compared to previous month mark?
{You must use multi-dimensional array for this problem.}

*/?>
<?php
$month = array("May"=>array("x"=>array("Tamil"=>55,"English"=>65,"Maths"=>75,"Science"=>50,"S. Science"=>80),
"y"=>array("Tamil"=>80,"English"=>52,"Maths"=>26,"Science"=>65,"S. Science"=>70),
"z"=>array("Tamil"=>48,"English"=>56,"Maths"=>85,"Science"=>49,"S. Science"=>59)),
"June"=>array("x"=>array("Tamil"=>65,"English"=>75,"Maths"=>56,"Science"=>84,"S. Science"=>65),
"y"=>array("Tamil"=>59,"English"=>57,"Maths"=>68,"Science"=>34,"S. Science"=>20),
"z"=>array("Tamil"=>48,"English"=>56,"Maths"=>56,"Science"=>75,"S. Science"=>64)
)
);

$topper = array();
foreach($month as $key=>$value)
{
$monthlist = $value;
//print_r($monthlist);
$totaltamil=0; $totaleng=0;
foreach($monthlist as $key1=>$value1)
{
$marklist = $value1;
//print_r($marklist);
$totallist=0;

$pass=1; $failedsubject=''; 
foreach($marklist as $key2=>$value2)
{
if($value2<=40)
{
$pass=0;
$failedsubject = $failedsubject . $key2;
//$failedsubject = test;
//echo $key2.'<br>';
}
if($key2=='Tamil')
{
$totaltamil = $totaltamil + $value2;
$totaltamil1 = $key2 . $totaltamil; 
//print_r($totaltamil);
}
if($key2=='English')
{
$totaleng = $totaleng + $value2;
$totaleng1 = $key2 . $totaleng; 
//print_r($totaltamil);
}


$totallist = $totallist + $value2;
}

$topper[$key][$key1]= $totallist/5;



echo 'Month : '. $key . ' '. 'Student : ' . $key1 . ' ' . 'Percentage : ' . $totallist/5 . '<br>';

if($pass==0)
{
echo 'fail';
}
else
{echo 'pass';}

echo $failedsubject;
echo '<br>';
echo '*************************************************';
echo '<br>';

}
echo 'Total Tamil Marks : '. $key . ' '  . $totaltamil1;
echo '<br>';


echo 'Total English Marks : '. $key . ' '  . $totaleng1;
echo '<br>';
echo '*************************************************';
echo '<br>';
}

//print_r($topper);
$x = $topper['May']['x'];
$y = $topper['May']['y'];
$z = $topper['May']['z'];
$x1 = $topper['June']['x'];
$y1 = $topper['June']['y'];
$z1 = $topper['June']['z'];

if($x>$y && $x>$z)
{
echo 'May month Student x topper' . $x;
}
else if($y>$z)
{
echo 'May month Student y topper' . $y;
}
else
{
echo 'May month Student z topper' . $z;
}
echo '<br>';
echo '*************************************************';
echo '<br>';
if($x1>$y1 && $x1>$z1)
{
echo 'June month Student x topper' . $x1;
}
else if($y1>$z1)
{
echo 'June month Student y topper' . $y1;
}
else
{
echo 'June month Student z topper' . $z1;
}

//echo $topper[$key][$key1];
/* $lagest = array();
$i=0;
foreach($may as $key=>$a) {
    if($i==0) $b=$a;
    if($b<$a) {
        $b=$a;
        $k=$key;
    }
    $i++;
 }
 $lagest[$k]=$b;
 print_r($lagest); */



//echo $month['june']['y']['Tamil'];
?>